package com.wolves.career.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wolves.career.entity.ProSchoolCategory;
import com.wolves.career.service.ProSchoolCategoryService;
import com.wolves.career.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 学校门类联系表 前端控制器
 * </p>
 *
 * @author 麦翔盛
 * @since 2021-10-31
 */
@RestController
@RequestMapping("/career/schoolCategory")
@CrossOrigin
public class ProSchoolCategoryController {
    @Autowired
    private ProSchoolCategoryService schoolCategoryService;

    @DeleteMapping("/{id}")
    public R removeProSchoolCategory(@PathVariable String id){
        schoolCategoryService.removeById(id);
        return R.ok();
    }

    @PostMapping("/schoolCategory")
    public R updateProSchoolCategory(@RequestBody ProSchoolCategory schoolCategory){
        schoolCategoryService.updateById(schoolCategory);
        return R.ok();
    }

    @PutMapping("/schoolCategory")
    public R addProSchoolCategory(@RequestBody ProSchoolCategory schoolCategory){
        schoolCategoryService.save(schoolCategory);
        return R.ok();
    }

    @PostMapping("/list/{pageNo}/{limit}")
    public R listSchoolCategory(@PathVariable long pageNo, @PathVariable long limit){
        Page<ProSchoolCategory> page = new Page<>(pageNo,limit);
        IPage<ProSchoolCategory> schoolCategoryPage = schoolCategoryService.page(page, null);
        return R.ok().data("records",schoolCategoryPage.getRecords()).data("total",schoolCategoryPage.getTotal());
    }

}

